﻿package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;

import vo.admin.AddUserPanelVO;
import vo.admin.MainPanelVO;
import logicInterface.AdminLogicInterface;
import main.Main;
import adminLogic.MockAdminLogic;


public class AddUserPanel extends MyPanel{

	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JScrollPane addpanelScrollPane;
	private JLabel pleaseaddLabel;
	private JLabel usernameaddLabel;
	private JTextField usernameaddField;
	private JLabel passwordaddLabel;
	private JPasswordField passwordaddField;
	private JLabel identityaddLabel;
	private JComboBox identityaddComboBox;
	private MyButton confirmaddButton;

	protected void initComponent() {
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		
		addpanelScrollPane = new JScrollPane(this);
		addpanelScrollPane.setBounds(300, 150, 500, 450);
		addpanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleaseaddLabel = new JLabel("请填写以下信息:");
		usernameaddLabel = new JLabel("用户名:");
		usernameaddField = new JTextField();
		passwordaddLabel = new JLabel("密码:");
		passwordaddField = new JPasswordField();
	    identityaddLabel = new JLabel("身份:");
	    identityaddComboBox = new JComboBox(new String[]{"会员","总经理","销售经理"});
	    confirmaddButton = new MyButton("添加用户");
	    pleaseaddLabel.setBounds(10, 20, 120, 20);
	    usernameaddLabel.setBounds(20, 60, 80, 20);
	    usernameaddField.setBounds(100, 60, 150, 25);
	    passwordaddLabel.setBounds(20, 100, 80, 20);
	    passwordaddField.setBounds(100, 100, 150, 25);
	    identityaddLabel.setBounds(20, 140, 80, 20);
	    identityaddComboBox.setBounds(100, 140, 100, 25);
	    confirmaddButton.setBounds(350, 140, 100, 40);
	    this.add(pleaseaddLabel);
	    this.add(usernameaddLabel);
	    this.add(usernameaddField);
	    this.add(passwordaddLabel);
	    this.add(passwordaddField);
	    this.add(identityaddLabel);
	    this.add(identityaddComboBox);
	    this.add(confirmaddButton);
	    
	    logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toMain");
		confirmaddButton.setButtonAction("addUser");
	}

	protected void updateVO() {
		AddUserPanelVO aupvo = null;
		try {
			aupvo = Main.getLogic().getAupvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		aupvo.setPassword(passwordaddField.getText());
		aupvo.setUsername(usernameaddField.getText());
		aupvo.setType(identityaddComboBox.getSelectedIndex());
		Main.getLogic().setAupvo(aupvo);
	}
}
